package io.renren.modules.ranking.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.ranking.entity.RoadAccidentsEntity;
import io.renren.modules.ranking.service.RoadAccidentsService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.common.utils.R;


/**
 * 
 * 
 * @author wxy
 * @email sharonwang_xy@163.com
 * @date 2018-10-24 21:52:01
 */
@RestController
@RequestMapping("ranking/roadaccidents")
public class RoadAccidentsController {
	@Autowired
	private RoadAccidentsService roadAccidentsService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("ranking:roadaccidents:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		List<RoadAccidentsEntity> roadAccidentsList = roadAccidentsService.queryList(query);
		int total = roadAccidentsService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(roadAccidentsList, total, query.getLimit(), query.getCurrPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("ranking:roadaccidents:info")
	public R info(@PathVariable("id") Integer id){
		RoadAccidentsEntity roadAccidents = roadAccidentsService.queryObject(id);
		
		return R.ok().put("roadAccidents", roadAccidents);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("ranking:roadaccidents:save")
	public R save(@RequestBody RoadAccidentsEntity roadAccidents){
		roadAccidentsService.save(roadAccidents);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("ranking:roadaccidents:update")
	public R update(@RequestBody RoadAccidentsEntity roadAccidents){
		roadAccidentsService.update(roadAccidents);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("ranking:roadaccidents:delete")
	public R delete(@RequestBody Integer[] ids){
		roadAccidentsService.deleteBatch(ids);
		
		return R.ok();
	}
	
}
